package com.bt.springboot.common.util;

import cn.hutool.core.date.LocalDateTimeUtil;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author zkx
 * @Date 2022/11/29 18:23
 */
public class DateUtil {


	public static List<LocalDate> getBetweenDate(LocalDate startDate, LocalDate endDate) {
		List<LocalDate> list = new ArrayList<>();
		long distance = ChronoUnit.DAYS.between(startDate, endDate);
		if (distance < 1) {
			return list;
		}
		Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance + 1).forEach(list::add);
		return list;
	}

	public static void main(String[] args) {
//		System.out.println(betweenTime(LocalDateTimeUtil.parse("2023-01-28T17:00:00"),LocalDateTime.now()));
		LocalDateTime time = LocalDateTimeUtil.parse("2023-01-28T17:00:00");
		System.out.println(time.format(DateTimeFormatter.ofPattern("yyyyMMdd")));
	}

	/**
	 * 计算时间差
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public static Long betweenTime(LocalDateTime startDate, LocalDateTime endDate){
//		LocalDateTimeUtil.between(startDate,endDate,ChronoUnit.MINUTES)

		return Duration.between(startDate,endDate).toMinutes();
	}
}
